/**
  ******************************************************************************
  * @author     Chris
  * @since      2023/10/11 14:41
  *
  * @file       hd_w25qxx.c
  * @brief      W25QXX Hardware Driver.
  *
  * @note       This file contains the hardware driver for the W25QXX.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date           Author       Notes
  *   2023/10/11     Chris        the first version
  *
  ******************************************************************************
  */

#include "hd_w25qxx.h"
#include "pd_s_spi.h"

/** region Declaration and Definition Region */

/** region Variables and Constants Region */

/** endregion */

/** region Function Declaration Region */

/** endregion */

/** endregion */


/** region Public Definition Region */

/**
 * @brief   W25QXX 初始化
 *
 * @note    1. 初始化 SPI
 *          2. 初始化 W25QXX
 * @param   无
 * @retval  无
 */
void HD_W25QXX_Init(void) {
    // 初始化 SPI1
    PD_S_SPI1_Init();

    // TODO W25QXX 初始化
}

/**
 * @brief   读取 W25QXX 寄存器
 *
 * @note    无
 * @param   无
 * @retval  无
 */
void HD_W25QXX_ReadID(uint8_t *MID, uint16_t *DID) {
    PD_S_SPI1_Start(SPI1_NSS_W25QXX);
    PD_S_SPI1_SwapByte(RDDID);
    *MID = PD_S_SPI1_SwapByte(0xFF);    // Dummy Read
    *MID = PD_S_SPI1_SwapByte(0xFF);    // ID1 Read
    *DID = PD_S_SPI1_SwapByte(0xFF);    // ID2 Read
    *DID <<= 8;
    *DID |= PD_S_SPI1_SwapByte(0xFF);    // ID2 Read
    PD_S_SPI1_Stop(SPI1_NSS_W25QXX);
}

/** endregion */


/** region Private Definition Region */

/** endregion */
